﻿namespace WMS6.Web.Outbound
{
    using System;
    using System.Collections.Generic;
    using System.Data;
    using System.Web.UI;
    using System.Web.UI.HtmlControls;
    using System.Web.UI.WebControls;
    using WMS6.Web;
    using WMS6.Web.BaseInfoServiceRef;
    using WMS6.Web.CommonMethodService2Ref;
    using WMS6.Web.CommonMethodServiceRef;
    using WMS6.Web.OutboundServiceRef;

    public class Shipping : BasePage
    {
        protected HtmlAnchor A1;
        protected HtmlAnchor aSendOrder;
        protected HtmlInputButton btnAction;
        protected Button btnActualShipDate;
        protected Button btnCancelShipping;
        protected Button btnEncaseAddDetail;
        protected Button btnEncaseClose;
        protected Button btnEncaseDeleteDetail;
        protected Button btnEncaseNesting;
        protected Button btnEncasePrint;
        protected Button btnGoBack;
        protected Button btnImportData;
        protected HtmlAnchor btnRefresh;
        protected Button btnReleasePrintShippingOrder;
        protected Button btnScanDelete;
        protected Button btnShipping;
        protected Button btnUpdateUdf;
        protected DropDownList ddlEncaseForm;
        protected DropDownList ddlEncaseTo;
        protected DropDownList ddlPriority;
        protected DropDownList ddlStatus;
        protected DropDownList ddlType;
        protected DropDownList ddlWareHouseID;
        protected HtmlForm F7061;
        protected GridView gvdShipmentContainer;
        protected GridView gvdShipmentContainers;
        protected GridView gvOrderDetail;
        protected GridView gvShippedDetail;
        protected HtmlInputHidden hdncalendarFlag;
        protected HtmlInputHidden hdnClickIndex;
        protected HtmlInputHidden hdnContainerID;
        protected HtmlInputHidden hdnCopy;
        protected HtmlInputHidden hdnCreatedBy;
        protected HtmlInputHidden hdnDataFormat;
        protected HtmlInputHidden hdnFlag;
        protected HtmlInputHidden hdnFrom;
        protected HtmlInputHidden hdnLineID;
        protected HtmlInputHidden hdnOrderID;
        protected HtmlInputHidden hdnOwnerID;
        protected HtmlInputHidden hdnPalletAudit;
        protected HtmlInputHidden hdnSelectIndex;
        protected HtmlInputHidden hdnTimeValue;
        protected HtmlHead Head1;
        protected HtmlInputButton htmlbtnReport;
        protected HtmlImage ImgactualShipDate;
        protected HtmlImage imgContainerType;
        protected HtmlImage imgOwnerID;
        protected Label lblActualShipDate;
        protected Label lblBarcode;
        protected Label lblCCompany;
        protected Label lblConsigneeID;
        protected Label lblContainerID;
        protected Label lblContainerType;
        protected Label lblDeliveryDate;
        protected Label lblExternOrderID;
        protected Label lblExternOrderID2;
        protected Label lblHeight;
        protected Label lblIntransitID;
        protected Label lblLength;
        protected Label lblMsg;
        protected Label lblOrderDate;
        protected Label lblOrderGroup;
        protected Label lblOrderID;
        protected Label lblOwner;
        protected Label lblOwnerID;
        protected Label lblPriority;
        protected Label lblQty;
        protected Label lblReferenceNum;
        protected Label lblRemark;
        protected Label lblRequestShipDate;
        protected Label lblSCTotal;
        protected Label lblSCTotalQty;
        protected Label lblShippedTotal;
        protected Label lblShippedTotalQty;
        protected Label lblSkuID;
        protected Label lblStatus;
        protected Label lblTotalAllcated;
        protected Label lblTotalAllcatedQty;
        protected Label lblTotalHeight;
        protected Label lblTotalHeightText;
        protected Label lblTotalLength;
        protected Label lblTotalLengthText;
        protected Label lblTotalOriginal;
        protected Label lblTotalOriginalQty;
        protected Label lblTotalPicked;
        protected Label lblTotalPickedQty;
        protected Label lblTotalPreallocated;
        protected Label lblTotalPreallocatedQty;
        protected Label lblTotalQty;
        protected Label lblTotalShipped;
        protected Label lblTotalShippedQty;
        protected Label lblTotalValue;
        protected Label lblTotalValueText;
        protected Label lblTotalVolume;
        protected Label lblTotalVolumeText;
        protected Label lblTotalWeight;
        protected Label lblTotalWeightText;
        protected Label lblTotalWidth;
        protected Label lblTotalWidthText;
        protected Label lblTye;
        protected Label lblValue;
        protected Label lblVolume;
        protected Label lblWareHouseID;
        protected Label lblWeight;
        protected Label lblWidth;
        protected LinkButton lnkbtnActualShipDate;
        protected LinkButton lnkbtnCancelShipping;
        protected LinkButton lnkbtnClose;
        protected LinkButton lnkbtnEncasingDetailNote;
        protected LinkButton lnkbtnEncasingNote;
        protected LinkButton lnkbtnInvPalletInput;
        protected LinkButton lnkbtnPrintCommoditySignoff;
        protected LinkButton lnkbtnPrintOutboundList;
        protected LinkButton lnkbtnPrintPaymentBill;
        protected LinkButton lnkbtnPrintReceivableBill;
        protected LinkButton lnkbtnShipping;
        protected LinkButton lnkbtnShippingOrder;
        protected LinkButton lnkbtnShippingOrderOCV;
        protected LinkButton lnkbtnUdf;
        protected HtmlLink mycss;
        protected Label one1;
        protected Label one2;
        protected Label one3;
        protected Label one4;
        protected Label one5;
        protected ScriptManager ScriptManager1;
        private decimal SCTotalQty;
        private decimal shippedTotalQty;
        protected HtmlTableCell tdlnkbtnActualShipDate;
        protected HtmlTableCell tdlnkbtnCancelShipping;
        protected HtmlTableCell tdlnkbtnClose;
        protected HtmlTableCell tdlnkbtnEncasingDetailNote;
        protected HtmlTableCell tdlnkbtnEncasingNote;
        protected HtmlTableCell tdlnkbtnInvPalletInput;
        protected HtmlTableCell tdlnkbtnPrintCommoditySignoff;
        protected HtmlTableCell tdlnkbtnPrintOutboundList;
        protected HtmlTableCell tdlnkbtnPrintPaymentBill;
        protected HtmlTableCell tdlnkbtnPrintReceivableBill;
        protected HtmlTableCell tdlnkbtnShipping;
        protected HtmlTableCell tdlnkbtnShippingOrder;
        protected HtmlTableCell tdlnkbtnShippingOrderOCV;
        protected HtmlTableCell tdlnkbtnUdf;
        private decimal TotalAllcatedQty;
        private decimal TotalHeight;
        private decimal TotalLength;
        private decimal TotalOriginalQty;
        private decimal TotalPickedQty;
        private decimal TotalPreallocatedQty;
        private decimal TotalShippedQty;
        private decimal TotalValue;
        private decimal TotalVolume;
        private decimal TotalWeight;
        private decimal TotalWidth;
        protected TextBox txtActualShipDate;
        protected HtmlInputText txtActualShipDate1;
        protected TextBox txtBarcode;
        protected TextBox txtCCompany;
        protected TextBox txtConsigneeID;
        protected TextBox txtContainerID;
        protected TextBox txtContainerType;
        protected TextBox txtDeliveryDate;
        protected TextBox txtExternOrderID;
        protected TextBox txtExternOrderID2;
        protected TextBox txtHeight;
        protected TextBox txtIntransitID;
        protected TextBox txtLength;
        protected TextBox txtOrderDate;
        protected TextBox txtOrderGroup;
        protected TextBox txtOrderID;
        protected TextBox txtOwnerID;
        protected TextBox txtQty;
        protected TextBox txtReferenceNum;
        protected TextBox txtRemark;
        protected TextBox txtRequestShipDate;
        protected TextBox txtSkuID;
        protected TextBox txtTotalQty;
        protected TextBox txtValue;
        protected TextBox txtVolume;
        protected TextBox txtWeight;
        protected TextBox txtWidth;

        protected void btnA1_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(this.hdnTimeValue.Value))
            {
                this.lblMsg.Text = "请选择实际发货时间！";
            }
            else
            {
                string CS40001 = this.hdnClickIndex.Value;
                if (CS40001 != null)
                {
                    if (!(CS40001 == "1"))
                    {
                        if (CS40001 == "2")
                        {
                            this.btnShipping_Click(sender, e);
                        }
                        else if ((CS40001 == "3") || (CS40001 == "4"))
                        {
                            this.btnActualShipDate_Click(sender, e);
                        }
                    }
                    else
                    {
                        this.SendOrder_Click(sender, e);
                    }
                }
                this.hdnTimeValue.Value = "";
            }
        }

        protected void btnActualShipDate_Click(object sender, EventArgs e)
        {
            Exception ex;
            string strTemp = string.Empty;
            if (!string.IsNullOrEmpty(this.hdnSelectIndex.Value))
            {
                List<string> LINE_ID = base.GetSelectedIDsInGridView(this.gvOrderDetail, "LINEID");
                try
                {
                    if ((LINE_ID != null) && (LINE_ID.Count > 0))
                    {
                        try
                        {
                            strTemp = OutboundServiceClientProxy.GetInstance().UpateActualShipDateByOrderIDLineID(this.txtOrderID.Text, LINE_ID, this.hdnTimeValue.Value);
                            if (!string.IsNullOrEmpty(strTemp))
                            {
                                this.lblMsg.Text = strTemp + "更新成功!";
                                this.hdnSelectIndex.Value = "";
                            }
                        }
                        catch (Exception exception1)
                        {
                            ex = exception1;
                            this.lblMsg.Text = ex.Message;
                        }
                        finally
                        {
                            ScriptManager.RegisterStartupScript(this.Page, base.GetType(), "", " <script type='text/javascript'> ActualShipClose();</script>", false);
                        }
                    }
                    else
                    {
                        this.lblMsg.Text = "请选择订单行!";
                        ScriptManager.RegisterStartupScript(this.Page, base.GetType(), "", " <script type='text/javascript'>setTab('one',2,5);ActualShipClose();</script>", false);
                    }
                }
                catch (Exception exception2)
                {
                    ex = exception2;
                    this.lblMsg.Text = ex.Message;
                }
            }
            else
            {
                try
                {
                    strTemp = OutboundServiceClientProxy.GetInstance().UpateActualShipDateByOrderID(this.txtOrderID.Text, this.hdnTimeValue.Value);
                    if (!string.IsNullOrEmpty(strTemp))
                    {
                        this.lblMsg.Text = strTemp + "更新成功!";
                        this.hdnSelectIndex.Value = "";
                    }
                }
                catch (Exception exception3)
                {
                    ex = exception3;
                    this.lblMsg.Text = ex.Message;
                }
                finally
                {
                    ScriptManager.RegisterStartupScript(this.Page, base.GetType(), "", " <script type='text/javascript'> ActualShipClose();</script>", false);
                }
            }
            if (!string.IsNullOrEmpty(strTemp))
            {
                this.SetShippingOrderInfo2From();
            }
        }

        protected void btnAddDetail_Click(object sender, EventArgs e)
        {
            base.Response.Redirect(string.Format("EncaseMent.aspx?from={0}&OrderID={1}&OwnerID={2}", this.hdnFrom.Value, this.txtOrderID.Text, this.txtOwnerID.Text), true);
        }

        protected void btnCancelShipping_Click(object sender, EventArgs e)
        {
            List<string> strStatus = base.GetSelectedIDsInGridView(this.gvOrderDetail, "STATUS");
            List<string> selectedLineID = base.GetSelectedIDsInGridView(this.gvOrderDetail, "LINEID");
            try
            {
                if (strStatus.Count > 0)
                {
                    int i;
                    for (i = 0; strStatus.Count > i; i++)
                    {
                        if ((strStatus[i].ToString().ToUpper() != "SHIPPED") && (strStatus[i].ToString().ToUpper() != "PARTSHIPPED"))
                        {
                            this.lblMsg.Text = selectedLineID[i] + "该单号未发货无法取消!";
                            return;
                        }
                    }
                    if (((selectedLineID != null) && (selectedLineID.Count > 0)) && !string.IsNullOrEmpty(OutboundServiceClientProxy.GetInstance().CancelShippingByOrderIDOrderLineID(this.txtOrderID.Text, selectedLineID)))
                    {
                        string temp = string.Empty;
                        for (i = 0; i < selectedLineID.Count; i++)
                        {
                            temp = temp + selectedLineID[i] + ",";
                        }
                        if (!string.IsNullOrEmpty(temp))
                        {
                            this.lblMsg.Text = "行项：" + temp.Substring(0, temp.Length - 1) + "取消发货成功!";
                        }
                        this.SetShippingOrderInfo2From();
                    }
                }
                else
                {
                    this.lblMsg.Text = base.GetGlobalMsgResource("F7500_003");
                }
            }
            catch (Exception ex)
            {
                this.lblMsg.Text = base.GetGlobalMsgResource("F7500_004") + ex.Message;
                SysLog.GetInstance().LogError(ex);
            }
            finally
            {
                ScriptManager.RegisterStartupScript(this.Page, base.GetType(), "", " <script type='text/javascript'> $.unblockUI();setTab('one',2,5);</script>", false);
            }
        }

        protected void btnDelete_Click(object sender, EventArgs e)
        {
            if (!string.IsNullOrEmpty(this.txtContainerID.Text))
            {
                List<string> InternalContainerID = base.GetSelectedIDsInGridView(this.gvdShipmentContainers, "InternalContainerID");
                if ((InternalContainerID == null) || (InternalContainerID.Count == 0))
                {
                    base.ShowMsgLabel(this.lblMsg, base.GetGlobalMsgResource("C008"));
                    ScriptManager.RegisterStartupScript(this.Page, base.GetType(), "ShippingPage", "<script language='javascript'>setTab('one',5,5);</script>", false);
                    return;
                }
                OutboundServiceClientProxy.GetInstance().DeleteShipmentContainer(InternalContainerID);
                base.ShowMsgLabel(this.lblMsg, base.GetGlobalMsgResource("F7600_026", new List<string> { this.txtContainerID.Text }));
                this.SetShippingOrderInfo2From();
                this.txtContainerID_OnTextChanged(null, null);
            }
            ScriptManager.RegisterStartupScript(this.Page, base.GetType(), "ShippingPage", "<script language='javascript'>setTab('one',5,5);</script>", false);
        }

        protected void btnDeleteDetail_Click(object sneder, EventArgs e)
        {
            List<string> ContainerIDs = base.GetSelectedIDsInGridView(this.gvdShipmentContainer, "ContainerID");
            List<string> TotalQty = base.GetSelectedIDsInGridView(this.gvdShipmentContainer, "TotalQty");
            for (int i = 0; TotalQty.Count > i; i++)
            {
                if (Convert.ToDecimal(TotalQty[i]) > 0M)
                {
                    this.lblMsg.Text = string.Format(base.GetGlobalMsgResource("F7600_010"), ContainerIDs[i]);
                    this.lblMsg.Visible = true;
                    ScriptManager.RegisterStartupScript(this.Page, base.GetType(), "ShippingPage", "<script language='javascript'>setTab('one',4,5);</script>", false);
                    return;
                }
            }
            List<string> InternalContainerIDs = base.GetSelectedIDsInGridView(this.gvdShipmentContainer, "InternalContainerID");
            string result = OutboundServiceClientProxy.GetInstance().DeleteShipmentContainer(InternalContainerIDs);
            this.lblMsg.Text = base.GetGlobalMsgResource("F7600_011");
            this.lblMsg.Visible = true;
            this.SetShippingOrderInfo2From();
            ScriptManager.RegisterStartupScript(this.Page, base.GetType(), "ShippingPage", "<script language='javascript'>setTab('one',4,5);</script>", false);
        }

        protected void btnEncasePrint_Click(object sender, EventArgs e)
        {
            List<string> ContainerIDs = base.GetSelectedIDsInGridView(this.gvdShipmentContainer, "ContainerID");
            if (ContainerIDs.Count <= 0)
            {
                this.lblMsg.Text = base.GetGlobalMsgResource("C008");
                this.lblMsg.Visible = true;
                ScriptManager.RegisterStartupScript(this.Page, base.GetType(), "", " <script type=\"text/javascript\" >setTab('one',4,5); </script>", false);
            }
            else if (ContainerIDs.Count > 1)
            {
                this.lblMsg.Text = base.GetGlobalMsgResource("C009");
                this.lblMsg.Visible = true;
                ScriptManager.RegisterStartupScript(this.Page, base.GetType(), "", " <script type=\"text/javascript\" >setTab('one',4,5); </script>", false);
            }
            else
            {
                this.hdnContainerID.Value = ContainerIDs[0];
                ScriptManager.RegisterStartupScript(this.Page, base.GetType(), "", " <script type=\"text/javascript\" >setTab('one',4,5);popPrintEncasingDetailNote2(); </script>", false);
            }
        }

        protected void btnGoBack_Click(object sender, EventArgs e)
        {
            base.Response.Redirect("ShippingQuery.aspx?FunctionID=7060", false);
        }

        protected void btnImportData_Click(object sender, EventArgs e)
        {
            try
            {
                if (!string.IsNullOrEmpty(this.txtOrderID.Text.Trim()))
                {
                    ScriptManager.RegisterStartupScript(this.Page, base.GetType(), "", "<script language='javascript'>setTab('one',4,5);ImporDataAuthentication('SHIPPINGCONTAINERDETAIL','" + this.txtOrderID.Text + "','" + this.txtOwnerID.Text + "');</script>", false);
                }
                this.SetShippingOrderInfo2From();
            }
            catch (Exception ex)
            {
                this.lblMsg.Text = ex.Message;
            }
            finally
            {
                ScriptManager.RegisterStartupScript(this.Page, base.GetType(), "", "<script language='javascript'>setTab('one',4,5);</script>", false);
            }
        }

        protected void btnRefresh_Click(object sender, EventArgs e)
        {
            this.SetShippingOrderInfo2From();
        }

        protected void btnReleasePrintShippingOrder_Click(object sender, EventArgs e)
        {
            try
            {
                List<PrintControlInfo> printControlInfos = new List<PrintControlInfo>();
                for (int i = 0; i < this.gvShippedDetail.Rows.Count; i++)
                {
                    if (((CheckBox) this.gvShippedDetail.Rows[i].FindControl("chbSelect")).Checked && (this.gvShippedDetail.DataKeys[i]["IsPrintedShippingOrder"].ToString().ToUpper() == "Y"))
                    {
                        PrintControlInfo printControlInfo = new PrintControlInfo {
                            PrintType = "PrintShippingOrder",
                            DocID = this.txtOrderID.Text.Trim(),
                            DocLineID = this.gvShippedDetail.DataKeys[i]["PickDetailID"].ToString()
                        };
                        printControlInfos.Add(printControlInfo);
                    }
                }
                if ((printControlInfos != null) && (printControlInfos.Count > 0))
                {
                    this.lblMsg.Text = string.Format("{0}打印已重置.", CommoneMethodService2ClientProxy.GetInstance().ReleasePrintControl(printControlInfos));
                    this.lblMsg.Visible = true;
                    this.SetShippingOrderInfo2From();
                }
                else
                {
                    this.lblMsg.Text = base.GetGlobalMsgResource("C008");
                    this.lblMsg.Visible = true;
                }
            }
            catch (Exception ex)
            {
                this.lblMsg.Text = ex.Message;
                this.lblMsg.Visible = true;
            }
            finally
            {
                ScriptManager.RegisterStartupScript(this.Page, base.GetType(), "", "<script language='javascript'>setTab('one',3,5);$.unblockUI();</script>", false);
            }
        }

        protected void btnShipping_Click(object sender, EventArgs e)
        {
            try
            {
                if (!string.IsNullOrEmpty(this.txtOrderID.Text.Trim()))
                {
                    int i;
                    string OrderIDs = this.txtOrderID.Text.Trim();
                    string errors = "";
                    List<string> LineIDs = new List<string>();
                    List<string> Statuss = new List<string>();
                    List<decimal> qtys = new List<decimal>();
                    for (i = 0; i < this.gvOrderDetail.Rows.Count; i++)
                    {
                        if (((CheckBox) this.gvOrderDetail.Rows[i].FindControl("chbSelect")).Checked)
                        {
                            LineIDs.Add(this.gvOrderDetail.DataKeys[i]["LINEID"].ToString());
                            Statuss.Add(this.gvOrderDetail.DataKeys[i]["STATUS"].ToString());
                            string strQty = ((TextBox) this.gvOrderDetail.Rows[i].FindControl("txtShipQty")).Text;
                            decimal qty = 0M;
                            if (string.IsNullOrEmpty(strQty))
                            {
                                errors = errors + string.Format(base.GetGlobalMsgResource("F7600_029"), this.gvOrderDetail.DataKeys[i]["LINEID"].ToString());
                            }
                            else if (!decimal.TryParse(strQty, out qty))
                            {
                                errors = errors + string.Format(base.GetGlobalMsgResource("F7600_030"), this.gvOrderDetail.DataKeys[i]["LINEID"].ToString());
                            }
                            else if (qty <= 0M)
                            {
                                errors = errors + string.Format(base.GetGlobalMsgResource("F7600_031"), this.gvOrderDetail.DataKeys[i]["LINEID"].ToString());
                            }
                            qtys.Add(qty);
                        }
                    }
                    if (!string.IsNullOrEmpty(errors))
                    {
                        this.lblMsg.Text = errors.Substring(0, errors.Length - 1);
                        this.lblMsg.Visible = true;
                    }
                    else if ((LineIDs == null) || (LineIDs.Count == 0))
                    {
                        base.ShowMsgLabel(this.lblMsg, base.GetGlobalMsgResource("F7600_006"));
                    }
                    else
                    {
                        if ((Statuss != null) && (Statuss.Count > 0))
                        {
                            for (i = 0; i < Statuss.Count; i++)
                            {
                                if (Statuss[i].ToString() == "Shipped")
                                {
                                    base.ShowMsgLabel(this.lblMsg, LineIDs[i].ToString() + base.GetGlobalMsgResource("F7600_007"));
                                    return;
                                }
                            }
                        }
                        string strTime = string.Empty;
                        if (string.IsNullOrEmpty(this.hdnTimeValue.Value))
                        {
                            strTime = "";
                        }
                        else
                        {
                            strTime = this.hdnTimeValue.Value;
                        }
                        if (!string.IsNullOrEmpty(OutboundService2ClientProxy.GetInstance().ShippedByOrderLineQty(OrderIDs, LineIDs, qtys, strTime)))
                        {
                            this.lblMsg.Text = string.Format(base.GetGlobalMsgResource("F7600_008"), this.txtOrderID.Text.Trim());
                        }
                        else
                        {
                            this.lblMsg.Text = string.Format(base.GetGlobalMsgResource("F7600_009"), this.txtOrderID.Text.Trim());
                        }
                        this.SetShippingOrderInfo2From();
                        if (this.ddlStatus.SelectedValue == "Shipped")
                        {
                            List<string> mailList = new List<string> {
                                DateTime.Now.ToString(),
                                this.txtOrderID.Text,
                                base.UserInfo.UserName
                            };
                            UserMstInfo user = BaseInfoServiceClientProxy.GetInstance().GetInfoByID(this.hdnCreatedBy.Value, "USER_MST") as UserMstInfo;
                            if (user != null)
                            {
                                base.SandMail("Shipping", mailList, user.Email);
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                SysLog.GetInstance().LogError(ex);
                this.lblMsg.Text = ex.Message;
            }
            finally
            {
                ScriptManager.RegisterStartupScript(this.Page, base.GetType(), "ShippingPage", "<script language='javascript'>setTab('one',2,5);$.unblockUI();</script>", false);
            }
        }

        protected void ddlEncaseForm_OnTextChanged(object sender, EventArgs e)
        {
            if (this.ddlEncaseForm.SelectedValue != "0")
            {
                string strContarnerID = this.ddlEncaseForm.SelectedValue;
                OrdersInfo orderInfo = base.DataEntityViewState as OrdersInfo;
                if (orderInfo.ShipmentContainerInfos.Count > 0)
                {
                    List<ShipmentContainerInfo> shipmentContainerList = orderInfo.ShipmentContainerInfos.FindAll(x => x.ContainerID != strContarnerID).FindAll(x => x.ParentContainerID != strContarnerID);
                    if (shipmentContainerList.Count > 0)
                    {
                        this.ddlEncaseTo.DataSource = shipmentContainerList;
                        this.ddlEncaseTo.DataTextField = "ContainerID";
                        this.ddlEncaseTo.DataValueField = "ContainerID";
                        this.ddlEncaseTo.DataBind();
                        this.ddlEncaseTo.Items.Insert(0, new ListItem("-----", "0"));
                        this.ddlEncaseTo.Items.Insert(this.ddlEncaseTo.Items.Count, new ListItem("清除嵌套", ""));
                    }
                }
            }
            ScriptManager.RegisterStartupScript(this.Page, base.GetType(), "ShippingPage", "<script language='javascript'>  document.getElementById('DivEncaseNesting').style.display=''; setTab('one',4,5); </script>", false);
        }

        protected void ddlType_SelectedIndexChanged(object sender, EventArgs e)
        {
            string CS40000 = this.ddlType.SelectedValue.ToUpper();
            if ((CS40000 != null) && (CS40000 == "TRANSFER"))
            {
                this.ddlWareHouseID.Visible = true;
                this.lblWareHouseID.Visible = true;
                this.txtIntransitID.Visible = true;
                this.lblIntransitID.Visible = true;
                this.lblConsigneeID.Visible = false;
                this.txtConsigneeID.Visible = false;
                this.lblCCompany.Visible = false;
                this.txtCCompany.Visible = false;
            }
            else
            {
                this.ddlWareHouseID.Visible = false;
                this.lblWareHouseID.Visible = false;
                this.txtIntransitID.Visible = false;
                this.lblIntransitID.Visible = false;
                this.lblConsigneeID.Visible = true;
                this.txtConsigneeID.Visible = true;
                this.lblCCompany.Visible = true;
                this.txtCCompany.Visible = true;
            }
            this.ddlWareHouseID.Enabled = false;
        }

        protected void Encase_Click(object sender, EventArgs e)
        {
            if ((this.ddlEncaseTo.SelectedValue != "0") && (this.ddlEncaseForm.SelectedValue != "0"))
            {
                base.ShowMsgLabel(this.lblMsg, OutboundServiceClientProxy.GetInstance().EncaseNesting(this.ddlEncaseForm.SelectedValue, this.ddlEncaseTo.SelectedValue));
            }
            else
            {
                base.ShowMsgLabel(this.lblMsg, base.GetGlobalMsgResource("F7600_027"));
            }
            this.ddlEncaseTo.Items.Clear();
            this.LoadData();
            ScriptManager.RegisterStartupScript(this.Page, base.GetType(), "ShippingPage", "<script language='javascript'>  setTab('one',4,5); </script>", false);
        }

        private void EncaseNesting()
        {
            OrdersInfo orderInfo = base.DataEntityViewState as OrdersInfo;
            if (orderInfo.ShipmentContainerInfos.Count > 0)
            {
                this.ddlEncaseForm.DataSource = orderInfo.ShipmentContainerInfos;
                this.ddlEncaseForm.DataTextField = "ContainerID";
                this.ddlEncaseForm.DataValueField = "ContainerID";
                this.ddlEncaseForm.DataBind();
                this.ddlEncaseForm.Items.Insert(0, new ListItem("-----", "0"));
            }
        }

        protected void gvdShipmentContainer_Init(object sender, EventArgs e)
        {
            base.InitDetailGridView("F7061", this.gvdShipmentContainer);
        }

        protected void gvdShipmentContainer_PageIndexChanging(object sender, GridViewPageEventArgs e)
        {
            (sender as GridView).PageIndex = e.NewPageIndex;
            (sender as GridView).DataSource = (base.DataEntityViewState as OrdersInfo).ShipmentContainerInfos;
            (sender as GridView).DataBind();
            ScriptManager.RegisterStartupScript(this.Page, base.GetType(), "ShippingPage", " <script type=\"text/javascript\" >setTab('one',5,5) </script>", false);
        }

        protected void gvdShipmentContainer_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                int i = this.gvdShipmentContainer.PageIndex * this.gvdShipmentContainer.PageSize;
                e.Row.Cells[0].Text = ((e.Row.RowIndex + 1) + i).ToString();
                if (((Label) e.Row.FindControl("lblQty")) != null)
                {
                    this.SCTotalQty += decimal.Parse(((Label) e.Row.FindControl("lblQty")).Text);
                }
                if (((Label) e.Row.FindControl("lblWeight")) != null)
                {
                    this.TotalWeight += decimal.Parse(((Label) e.Row.FindControl("lblWeight")).Text);
                }
                if (((Label) e.Row.FindControl("lblVolume")) != null)
                {
                    this.TotalVolume += decimal.Parse(((Label) e.Row.FindControl("lblVolume")).Text);
                }
                if (((Label) e.Row.FindControl("lblValue")) != null)
                {
                    this.TotalValue += decimal.Parse(((Label) e.Row.FindControl("lblValue")).Text);
                }
                if (((Label) e.Row.FindControl("lblLength")) != null)
                {
                    this.TotalLength += decimal.Parse(((Label) e.Row.FindControl("lblLength")).Text);
                }
                if (((Label) e.Row.FindControl("lbl_Weight")) != null)
                {
                    this.TotalWidth += decimal.Parse(((Label) e.Row.FindControl("lbl_Weight")).Text);
                }
                if (((Label) e.Row.FindControl("lblHeight")) != null)
                {
                    this.TotalHeight += decimal.Parse(((Label) e.Row.FindControl("lblHeight")).Text);
                }
            }
            if (e.Row.RowType == DataControlRowType.Footer)
            {
                this.lblSCTotalQty.Text = base.GetPreferenceDigit(this.SCTotalQty);
                this.lblTotalWeightText.Text = base.GetPreferenceDigit(this.TotalWeight);
                this.lblTotalVolumeText.Text = base.GetPreferenceDigit(this.TotalVolume);
                this.lblTotalValueText.Text = base.GetPreferenceDigit(this.TotalValue);
                this.lblTotalLengthText.Text = base.GetPreferenceDigit(this.TotalLength);
                this.lblTotalWidthText.Text = base.GetPreferenceDigit(this.TotalWidth);
                this.lblTotalHeightText.Text = base.GetPreferenceDigit(this.TotalHeight);
            }
        }

        protected void gvdShipmentContainer_Sorting(object sender, GridViewSortEventArgs e)
        {
            try
            {
                string sortDirection = string.Empty;
                if (base.GridViewSortDirection == SortDirection.Ascending)
                {
                    base.GridViewSortDirection = SortDirection.Descending;
                    sortDirection = "DESC";
                }
                else
                {
                    base.GridViewSortDirection = SortDirection.Ascending;
                    sortDirection = "ASC";
                }
                OrdersInfo ordersInfo = base.DataEntityViewState as OrdersInfo;
                DataView dv = CADataConverter.ToDataTable(ordersInfo.ShipmentContainerInfos).DefaultView;
                dv.Sort = e.SortExpression + " " + sortDirection;
                base.BindData2GridView(this.gvdShipmentContainer, dv);
            }
            catch (Exception ex)
            {
                base.ShowMsgLabel(this.lblMsg, ex.Message);
            }
            finally
            {
                ScriptManager.RegisterStartupScript(this.Page, base.GetType(), "ShippingPage", "<script language='javascript'>setTab('one',4,5);</script>", false);
            }
        }

        protected void gvdShipmentContainers_Init(object sender, EventArgs e)
        {
            base.InitDetailGridView("F7061", this.gvdShipmentContainer);
        }

        protected void gvdShipmentContainers_Sorting(object sender, GridViewSortEventArgs e)
        {
            try
            {
                string sortDirection = string.Empty;
                if (base.GridViewSortDirection == SortDirection.Ascending)
                {
                    base.GridViewSortDirection = SortDirection.Descending;
                    sortDirection = "DESC";
                }
                else
                {
                    base.GridViewSortDirection = SortDirection.Ascending;
                    sortDirection = "ASC";
                }
                OrdersInfo ordersInfo = base.PageQueryEntityViewState as OrdersInfo;
                DataView dv = CADataConverter.ToDataTable(ordersInfo.ShipmentContainerInfos).DefaultView;
                dv.Sort = e.SortExpression + " " + sortDirection;
                base.BindData2GridView(this.gvdShipmentContainers, dv);
            }
            catch (Exception ex)
            {
                base.ShowMsgLabel(this.lblMsg, ex.Message);
            }
            finally
            {
                ScriptManager.RegisterStartupScript(this.Page, base.GetType(), "ShippingPage", "<script language='javascript'>setTab('one',4,5);</script>", false);
            }
        }

        protected void gvOrderDetail_Init(object sender, EventArgs e)
        {
            base.InitDetailGridView("F7061", this.gvOrderDetail);
        }

        protected void gvOrderDetail_PageIndexChanging(object sender, GridViewPageEventArgs e)
        {
            (sender as GridView).PageIndex = e.NewPageIndex;
            (sender as GridView).DataSource = (base.DataEntityViewState as OrdersInfo).OrderDetailInfos;
            (sender as GridView).DataBind();
            ScriptManager.RegisterStartupScript(this.Page, base.GetType(), "ShippingPage", " <script type=\"text/javascript\" >setTab('one',2,5) </script>", false);
        }

        protected void gvOrderDetail_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                int i = this.gvOrderDetail.PageIndex * this.gvOrderDetail.PageSize;
                e.Row.Cells[0].Text = ((e.Row.RowIndex + 1) + i).ToString();
                ((CheckBox) e.Row.FindControl("chbSelect")).Attributes.Add("onclick", "SetRowIndex(" + e.Row.RowIndex + ")");
                base.SetGridViewLongTextLabel((Label) e.Row.FindControl("lblSkuDescr"));
                if (((Label) e.Row.FindControl("lblORIGINALQTY")) != null)
                {
                    this.TotalOriginalQty += decimal.Parse(((Label) e.Row.FindControl("lblORIGINALQTY")).Text);
                }
                if (((Label) e.Row.FindControl("lblPREALLOCATEDQTY")) != null)
                {
                    this.TotalPreallocatedQty += decimal.Parse(((Label) e.Row.FindControl("lblPREALLOCATEDQTY")).Text);
                }
                if (((Label) e.Row.FindControl("lblALLOCATEDQTY")) != null)
                {
                    this.TotalAllcatedQty += decimal.Parse(((Label) e.Row.FindControl("lblALLOCATEDQTY")).Text);
                }
                if (((Label) e.Row.FindControl("lblPICKEDQTY")) != null)
                {
                    this.TotalPickedQty += decimal.Parse(((Label) e.Row.FindControl("lblPICKEDQTY")).Text);
                }
                if (((Label) e.Row.FindControl("lblSHIPPEDQTY")) != null)
                {
                    this.TotalShippedQty += decimal.Parse(((Label) e.Row.FindControl("lblSHIPPEDQTY")).Text);
                }
            }
            if (e.Row.RowType == DataControlRowType.Footer)
            {
                this.lblTotalOriginalQty.Text = base.GetPreferenceDigit(this.TotalOriginalQty);
                this.lblTotalPreallocatedQty.Text = base.GetPreferenceDigit(this.TotalPreallocatedQty);
                this.lblTotalAllcatedQty.Text = base.GetPreferenceDigit(this.TotalAllcatedQty);
                this.lblTotalPickedQty.Text = base.GetPreferenceDigit(this.TotalPickedQty);
                this.lblTotalShippedQty.Text = base.GetPreferenceDigit(this.TotalShippedQty);
            }
        }

        protected void gvOrderDetail_Sorting(object sender, GridViewSortEventArgs e)
        {
            try
            {
                string sortDirection = string.Empty;
                if (base.GridViewSortDirection == SortDirection.Ascending)
                {
                    base.GridViewSortDirection = SortDirection.Descending;
                    sortDirection = "DESC";
                }
                else
                {
                    base.GridViewSortDirection = SortDirection.Ascending;
                    sortDirection = "ASC";
                }
                OrdersInfo ordersInfo = base.DataEntityViewState as OrdersInfo;
                DataView dv = CADataConverter.ToDataTable(ordersInfo.OrderDetailInfos).DefaultView;
                dv.Sort = e.SortExpression + " " + sortDirection;
                base.BindData2GridView(this.gvOrderDetail, dv);
            }
            catch (Exception ex)
            {
                base.ShowMsgLabel(this.lblMsg, ex.Message);
            }
            finally
            {
                ScriptManager.RegisterStartupScript(this.Page, base.GetType(), "ShippingPage", "<script language='javascript'>setTab('one',2,5);</script>", false);
            }
        }

        protected void gvShippedDetail_Init(object sender, EventArgs e)
        {
            base.InitDetailGridView("F7061", this.gvShippedDetail);
        }

        protected void gvShippedDetail_PageIndexChanging(object sender, GridViewPageEventArgs e)
        {
            (sender as GridView).PageIndex = e.NewPageIndex;
            (sender as GridView).DataSource = (base.DataEntityViewState as OrdersInfo).PickDetailInfos;
            (sender as GridView).DataBind();
            ScriptManager.RegisterStartupScript(this.Page, base.GetType(), "", " <script type=\"text/javascript\" >setTab('one',3,5) </script>", false);
        }

        protected void gvShippedDetail_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                int i = this.gvShippedDetail.PageIndex * this.gvShippedDetail.PageSize;
                e.Row.Cells[0].Text = ((e.Row.RowIndex + 1) + i).ToString();
                if (((Label) e.Row.FindControl("lblQty")) != null)
                {
                    this.shippedTotalQty += decimal.Parse(((Label) e.Row.FindControl("lblQty")).Text);
                }
            }
            if (e.Row.RowType == DataControlRowType.Footer)
            {
                this.lblShippedTotalQty.Text = base.GetPreferenceDigit(this.shippedTotalQty);
            }
        }

        protected void gvShippedDetail_Sorting(object sender, GridViewSortEventArgs e)
        {
            try
            {
                string sortDirection = string.Empty;
                if (base.GridViewSortDirection == SortDirection.Ascending)
                {
                    base.GridViewSortDirection = SortDirection.Descending;
                    sortDirection = "DESC";
                }
                else
                {
                    base.GridViewSortDirection = SortDirection.Ascending;
                    sortDirection = "ASC";
                }
                OrdersInfo ordersInfo = base.DataEntityViewState as OrdersInfo;
                DataView dv = CADataConverter.ToDataTable(ordersInfo.PickDetailInfos).DefaultView;
                dv.Sort = e.SortExpression + " " + sortDirection;
                base.BindData2GridView(this.gvShippedDetail, dv);
            }
            catch (Exception ex)
            {
                this.lblMsg.Text = ex.Message;
            }
            finally
            {
                ScriptManager.RegisterStartupScript(this.Page, base.GetType(), "", "<script language='javascript'>setTab('one',3,5);</script>", false);
            }
        }

        private void InsertShipmentContainerData()
        {
            string strType = string.Empty;
            if (!string.IsNullOrEmpty(this.txtQty.Text) && (this.txtQty.Text != "0"))
            {
                if (string.IsNullOrEmpty(this.txtContainerID.Text))
                {
                    base.ShowMsgLabel(this.lblMsg, base.GetGlobalMsgResource("F7600_021"));
                    this.txtBarcode.Text = "";
                    return;
                }
                if (string.IsNullOrEmpty(this.txtContainerType.Text))
                {
                    base.ShowMsgLabel(this.lblMsg, base.GetGlobalMsgResource("F7600_022"));
                    this.txtBarcode.Text = "";
                    return;
                }
                if (string.IsNullOrEmpty(this.txtQty.Text) && (this.txtQty.Text != "0"))
                {
                    base.ShowMsgLabel(this.lblMsg, base.GetGlobalMsgResource("F7600_023"));
                    this.txtBarcode.Text = "";
                    return;
                }
                OrdersInfo orderInfo = this.Session["PageOrderInfo"] as OrdersInfo;
                if (orderInfo.OrderDetailInfos.Count > 0)
                {
                    decimal dqty = Convert.ToDecimal(this.txtQty.Text);
                    List<ShipmentContainerInfo> shipmentContainerList = new List<ShipmentContainerInfo>();
                    for (int i = 0; orderInfo.OrderDetailInfos.Count > i; i++)
                    {
                        if (dqty <= 0M)
                        {
                            break;
                        }
                        if (orderInfo.OrderDetailInfos[i].SkuID.ToUpper() == this.txtSkuID.Text.ToUpper())
                        {
                            strType = "1";
                            if (orderInfo.OrderDetailInfos[i].UnEncasedQty == 0M)
                            {
                                strType = "1";
                                continue;
                            }
                            ShipmentContainerInfo shipmentContainerInfo = new ShipmentContainerInfo {
                                ContainerID = this.txtContainerID.Text,
                                ContainerType = this.txtContainerType.Text,
                                OrderID = orderInfo.OrderDetailInfos[i].OrderID,
                                OrderLineID = orderInfo.OrderDetailInfos[i].LineID
                            };
                            if (!string.IsNullOrEmpty(this.txtValue.Text))
                            {
                                shipmentContainerInfo.Value = Convert.ToDouble(this.txtValue.Text);
                            }
                            else
                            {
                                shipmentContainerInfo.Value = Convert.ToDouble("0");
                            }
                            if (!string.IsNullOrEmpty(this.txtVolume.Text))
                            {
                                shipmentContainerInfo.Volume = Convert.ToDouble(this.txtVolume.Text);
                            }
                            else
                            {
                                shipmentContainerInfo.Volume = Convert.ToDouble("0");
                            }
                            if (!string.IsNullOrEmpty(this.txtWeight.Text))
                            {
                                shipmentContainerInfo.Weight = Convert.ToDouble(this.txtWeight.Text);
                            }
                            else
                            {
                                shipmentContainerInfo.Weight = Convert.ToDouble("0");
                            }
                            if (!string.IsNullOrEmpty(this.txtWidth.Text))
                            {
                                shipmentContainerInfo.Width = Convert.ToDouble(this.txtWidth.Text);
                            }
                            else
                            {
                                shipmentContainerInfo.Width = Convert.ToDouble("0");
                            }
                            if (!string.IsNullOrEmpty(this.txtLength.Text))
                            {
                                shipmentContainerInfo.Length = Convert.ToDouble(this.txtLength.Text);
                            }
                            else
                            {
                                shipmentContainerInfo.Length = Convert.ToDouble("0");
                            }
                            shipmentContainerInfo.Remark = this.txtRemark.Text;
                            if (orderInfo.OrderDetailInfos[i].UnEncasedQty > dqty)
                            {
                                shipmentContainerInfo.Qty = orderInfo.OrderDetailInfos[i].UnEncasedQty - (orderInfo.OrderDetailInfos[i].UnEncasedQty - dqty);
                                orderInfo.OrderDetailInfos[i].UnEncasedQty -= dqty;
                                dqty = 0M;
                            }
                            else if (orderInfo.OrderDetailInfos[i].UnEncasedQty == dqty)
                            {
                                shipmentContainerInfo.Qty = dqty;
                                orderInfo.OrderDetailInfos[i].UnEncasedQty = 0M;
                                dqty = 0M;
                            }
                            else
                            {
                                decimal QtyCount = 0M;
                                string StrType = string.Empty;
                                foreach (OrderDetailInfo info in orderInfo.OrderDetailInfos)
                                {
                                    if (info.SkuID.ToUpper() == this.txtSkuID.Text.ToUpper())
                                    {
                                        QtyCount += info.UnEncasedQty;
                                        if (QtyCount >= dqty)
                                        {
                                            StrType = "OK";
                                            break;
                                        }
                                    }
                                }
                                if (StrType == "OK")
                                {
                                    shipmentContainerInfo.Qty = orderInfo.OrderDetailInfos[i].UnEncasedQty;
                                    dqty -= orderInfo.OrderDetailInfos[i].UnEncasedQty;
                                    orderInfo.OrderDetailInfos[i].UnEncasedQty = 0M;
                                }
                            }
                            shipmentContainerInfo.TotalQty += Convert.ToDecimal(shipmentContainerInfo.Qty);
                            shipmentContainerInfo.SkuID = this.txtSkuID.Text;
                            shipmentContainerInfo.UomID = orderInfo.OrderDetailInfos[i].UomID;
                            shipmentContainerInfo.OwnerID = orderInfo.OrderDetailInfos[i].OwnerID;
                            shipmentContainerInfo.MultiFlag = "Y";
                            shipmentContainerInfo.IsActive = "Y";
                            shipmentContainerInfo.Status = "OK";
                            shipmentContainerInfo.CreatedBy = base.UserInfo.UserID;
                            shipmentContainerInfo.ExternOrderID = orderInfo.OrderDetailInfos[i].ExternOrderID;
                            shipmentContainerInfo.ExternLineID = orderInfo.OrderDetailInfos[i].ExternLineID;
                            shipmentContainerList.Add(shipmentContainerInfo);
                            continue;
                        }
                        if (string.IsNullOrEmpty(strType))
                        {
                            strType = "2";
                        }
                    }
                    if (dqty == 0M)
                    {
                        if (shipmentContainerList.Count > 0)
                        {
                            try
                            {
                                OutboundServiceClientProxy.GetInstance().ScanShipmentContainer(shipmentContainerList);
                                this.txtBarcode.Text = "";
                                this.txtSkuID.Text = "";
                                ScriptManager.RegisterStartupScript(this.Page, base.GetType(), "Succeed", "<script language='javascript'> playvoice('../Sounds/S2.mp3');</script>", false);
                            }
                            catch (Exception ex)
                            {
                                base.ShowMsgLabel(this.lblMsg, ex.Message);
                                ScriptManager.RegisterStartupScript(this.Page, base.GetType(), "Unsuccessfully", "<script language='javascript'> playvoice('../Sounds/S1.mp3');</script>", false);
                            }
                            this.SetShippingOrderInfo2From();
                            this.txtContainerID_OnTextChanged(null, null);
                            this.txtBarcode.Focus();
                        }
                    }
                    else
                    {
                        if ((strType == "1") || (dqty > 0M))
                        {
                            base.ShowMsgLabel(this.lblMsg, base.GetGlobalMsgResource("F7600_024", new List<string> { this.txtSkuID.Text }));
                            this.txtQty.Focus();
                            ScriptManager.RegisterStartupScript(this.Page, base.GetType(), "Unsuccessfully", "<script language='javascript'> playvoice('../Sounds/S1.mp3');</script>", false);
                        }
                        if (strType == "2")
                        {
                            base.ShowMsgLabel(this.lblMsg, base.GetGlobalMsgResource("F7600_025", new List<string> { this.txtSkuID.Text }));
                            this.txtBarcode.Focus();
                            ScriptManager.RegisterStartupScript(this.Page, base.GetType(), "Unsuccessfully", "<script language='javascript'> playvoice('../Sounds/S1.mp3');</script>", false);
                        }
                        this.txtBarcode.Text = "";
                        return;
                    }
                }
            }
            ScriptManager.RegisterStartupScript(this.Page, base.GetType(), "ShippingPage", "<script language='javascript'>setTab('one',5,5);</script>", false);
        }

        protected void lnkbtnCancelShipping_Click(object sender, EventArgs e)
        {
            try
            {
                if ((this.ddlStatus.SelectedValue == "PartShipped") || (this.ddlStatus.SelectedValue == "Shipped"))
                {
                    if (string.IsNullOrEmpty(OutboundServiceClientProxy.GetInstance().CancelShippingByOrderID(new List<string> { this.txtOrderID.Text })))
                    {
                        string temp = this.txtOrderID.Text;
                        this.lblMsg.Text = temp.Substring(0, temp.Length - 1) + "取消发货成功!";
                        this.SetShippingOrderInfo2From();
                    }
                }
                else
                {
                    this.lblMsg.Text = "单据未发货,无法取消发货记录!";
                }
            }
            catch (Exception ex)
            {
                this.lblMsg.Text = base.GetGlobalMsgResource("F7500_004") + ex.Message;
                SysLog.GetInstance().LogError(ex);
            }
            finally
            {
                ScriptManager.RegisterStartupScript(this.Page, base.GetType(), "", " <script type='text/javascript'> $.unblockUI();setTab('one',2,5);</script>", false);
            }
        }

        protected void lnkbtnClose_Click(object sender, EventArgs e)
        {
            try
            {
                List<string> gInitLocala = new List<string> {
                    this.txtOrderID.Text
                };
                string strMsg = OutboundServiceClientProxy.GetInstance().ClosedByOrderID(gInitLocala);
                if (!string.IsNullOrEmpty(strMsg))
                {
                    this.lblMsg.Text = strMsg + base.GetGlobalMsgResource("F7600_028");
                    this.SetShippingOrderInfo2From();
                }
            }
            catch (Exception ex)
            {
                SysLog.GetInstance().LogError(ex);
                this.lblMsg.Text = ex.Message;
                this.lblMsg.Visible = true;
            }
        }

        protected void lnkbtnShippingOrder_Click(object sender, EventArgs e)
        {
            this.lblMsg.Visible = false;
            try
            {
                PrintControlInfo printControlInfo;
                this.Session.Remove("PRINT_SHIPPINGORDER_PICKDETAILIDS");
                List<string> pickDetailIDs = new List<string>();
                List<PrintControlInfo> printControlInfos = new List<PrintControlInfo>();
                string msg = string.Empty;
                string tempPickDetailIDsPrinted = string.Empty;
                for (int i = 0; i < this.gvShippedDetail.Rows.Count; i++)
                {
                    if (((CheckBox) this.gvShippedDetail.Rows[i].FindControl("chbSelect")).Checked)
                    {
                        if (this.gvShippedDetail.DataKeys[i]["IsPrintedShippingOrder"].ToString().ToUpper() != "Y")
                        {
                            pickDetailIDs.Add(this.gvShippedDetail.DataKeys[i]["PickDetailID"].ToString());
                            printControlInfo = new PrintControlInfo {
                                PrintType = "PrintShippingOrder",
                                DocID = this.txtOrderID.Text.Trim(),
                                DocLineID = this.gvShippedDetail.DataKeys[i]["PickDetailID"].ToString()
                            };
                            printControlInfos.Add(printControlInfo);
                        }
                        else
                        {
                            tempPickDetailIDsPrinted = tempPickDetailIDsPrinted + this.gvShippedDetail.DataKeys[i]["PickDetailID"].ToString() + ",";
                        }
                    }
                }
                if (!string.IsNullOrEmpty(tempPickDetailIDsPrinted))
                {
                    msg = msg + tempPickDetailIDsPrinted.Substring(0, tempPickDetailIDsPrinted.Length - 1) + "已打印.";
                }
                if (!string.IsNullOrEmpty(msg))
                {
                    this.lblMsg.Text = msg;
                    this.lblMsg.Visible = true;
                }
                else
                {
                    if (pickDetailIDs.Count <= 0)
                    {
                        OrdersInfo orderInfo = base.DataEntityViewState as OrdersInfo;
                        foreach (PickDetailInfo pickDetailInfo in orderInfo.ShippedDetailInfos)
                        {
                            if (pickDetailInfo.IsPrintedShippingOrder != "Y")
                            {
                                pickDetailIDs.Add(pickDetailInfo.PickDetailID);
                                printControlInfo = new PrintControlInfo {
                                    PrintType = "PrintShippingOrder",
                                    DocID = pickDetailInfo.OrderID,
                                    DocLineID = pickDetailInfo.PickDetailID
                                };
                                printControlInfos.Add(printControlInfo);
                            }
                        }
                    }
                    if (pickDetailIDs.Count <= 0)
                    {
                        this.lblMsg.Text = "没有可打印的记录.";
                        this.lblMsg.Visible = true;
                    }
                    else
                    {
                        this.Session["PRINT_SHIPPINGORDER_PICKDETAILIDS"] = pickDetailIDs;
                        ScriptManager.RegisterStartupScript(this.Page, base.GetType(), "", "<script language='javascript'>setTab('one',3,5);popPrintShippingOrder();</script>", false);
                        CommoneMethodService2ClientProxy.GetInstance().SavePrintControl(printControlInfos);
                        this.SetShippingOrderInfo2From();
                    }
                }
            }
            catch (Exception ex)
            {
                SysLog.GetInstance().LogError(ex);
                this.lblMsg.Text = ex.Message;
                this.lblMsg.Visible = true;
            }
            finally
            {
                ScriptManager.RegisterStartupScript(this.Page, base.GetType(), "", "<script language='javascript'>setTab('one',3,5);</script>", false);
            }
        }

        protected void lnkbtnShippingOrderOCV_Click(object sender, EventArgs e)
        {
            this.lblMsg.Visible = false;
            try
            {
                this.Session.Remove("PRINT_SHIPPINGORDER_PICKDETAILIDS");
                List<string> pickDetailIDs = new List<string>();
                OrdersInfo orderInfo = base.DataEntityViewState as OrdersInfo;
                foreach (PickDetailInfo pickDetailInfo in orderInfo.ShippedDetailInfos)
                {
                    pickDetailIDs.Add(pickDetailInfo.PickDetailID);
                }
                this.Session["PRINT_SHIPPINGORDER_PICKDETAILIDS"] = pickDetailIDs;
                ScriptManager.RegisterStartupScript(this.Page, base.GetType(), "", "<script language='javascript'>setTab('one',3,5);popPrintShippingOrderOCV();</script>", false);
                this.SetShippingOrderInfo2From();
            }
            catch (Exception ex)
            {
                SysLog.GetInstance().LogError(ex);
                this.lblMsg.Text = ex.Message;
                this.lblMsg.Visible = true;
            }
            finally
            {
                ScriptManager.RegisterStartupScript(this.Page, base.GetType(), "", "<script language='javascript'>setTab('one',3,5);</script>", false);
            }
        }

        protected void lnkbtnUdf_Click(object sender, EventArgs e)
        {
            try
            {
                this.Session["ShippingUdf"] = null;
                if (this.gvOrderDetail.Rows.Count > 0)
                {
                    List<OrderDetailInfo> orderDetailInfos = (base.DataEntityViewState as OrdersInfo).OrderDetailInfos;
                    if (this.hdnSelectIndex.Value == "1")
                    {
                        List<OrderDetailInfo> newOrderDetailInfo = new List<OrderDetailInfo>();
                        for (int i = 0; i < this.gvOrderDetail.Rows.Count; i++)
                        {
                            if (((CheckBox) this.gvOrderDetail.Rows[i].FindControl("chbSelect")).Checked)
                            {
                                foreach (OrderDetailInfo info in orderDetailInfos)
                                {
                                    if (this.gvOrderDetail.DataKeys[i]["LINEID"].ToString() == info.LineID.ToString())
                                    {
                                        newOrderDetailInfo.Add(info);
                                    }
                                }
                            }
                        }
                        if (newOrderDetailInfo.Count == 0)
                        {
                            this.lblMsg.Text = "请选择要更新的明细行项！";
                            return;
                        }
                        orderDetailInfos = newOrderDetailInfo;
                    }
                    if (orderDetailInfos != null)
                    {
                        this.Session["ShippingUdf"] = orderDetailInfos;
                        ScriptManager.RegisterStartupScript(this.Page, base.GetType(), "", "<script language='javascript'> popShippingUDF(); </script>", false);
                    }
                    else
                    {
                        this.lblMsg.Text = "未找到合适的数据源！";
                    }
                }
            }
            catch (Exception ex)
            {
                this.lblMsg.Text = "操作失败：" + ex.Message;
            }
            finally
            {
                this.hdnSelectIndex.Value = "";
                ScriptManager.RegisterStartupScript(this.Page, base.GetType(), "", "<script language='javascript'>setTab('one',2,5); </script>", false);
            }
        }

        private void LoadData()
        {
            this.txtOrderDate.Text = base.GetPreferenceShortDate(DateTime.Now);
            this.txtRequestShipDate.Text = base.GetPreferenceShortDate(DateTime.Now);
            this.txtActualShipDate.Text = base.GetPreferenceShortDate(DateTime.Now);
            this.txtDeliveryDate.Text = base.GetPreferenceShortDate(DateTime.Now);
            base.BindData2DDLBySysCode(this.ddlType, "OrderType");
            base.BindData2DDLBySysCode(this.ddlStatus, "OrderStatus");
            base.BindData2DDLBySysCode(this.ddlPriority, "OrderPriority");
            base.BindData2DDL4UserPermissionWareHouse(this.ddlWareHouseID);
            SysSettingInfo sysSetting = BaseInfoServiceClientProxy.GetInstance().GetInfoByID("AllowChangeActualShipDate", "SYS_SETTING") as SysSettingInfo;
            if ((sysSetting != null) && (sysSetting.Value == "Y"))
            {
                this.lnkbtnShipping.OnClientClick = "ShippingOrderByOrderID();return false;";
                this.btnShipping.OnClientClick = "ShippingOrderByOrderIDLineID(); return false;";
            }
            if (!string.IsNullOrEmpty(base.Request.QueryString["ID"]))
            {
                this.hdnOrderID.Value = base.Request.QueryString["ID"].ToString();
                this.SetShippingOrderInfo2From();
                this.hdnFlag.Value = "1";
            }
            if (!string.IsNullOrEmpty(base.Request.QueryString["from"]))
            {
                this.hdnFrom.Value = base.Request.QueryString["from"].ToString();
            }
            if (!string.IsNullOrEmpty(base.Request.QueryString["Tab"]))
            {
                ScriptManager.RegisterStartupScript(this.Page, base.GetType(), "", "<script language='javascript'>setTab('one'," + base.Request.QueryString["Tab"] + ",5);</script>", false);
            }
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!base.IsPostBack)
            {
                base.InitPage(this.Page);
                this.LoadData();
                this.Session.Remove("PageOrderInfo");
            }
            this.lblMsg.Text = "";
        }

        protected void SendOrder_Click(object sender, EventArgs e)
        {
            try
            {
                if (!string.IsNullOrEmpty(this.txtOrderID.Text))
                {
                    List<string> OrderIDs = new List<string> {
                        this.txtOrderID.Text.Trim()
                    };
                    if ((OrderIDs == null) || (OrderIDs.Count == 0))
                    {
                        base.ShowMsgLabel(this.lblMsg, base.GetGlobalMsgResource("F7600_006"));
                    }
                    else
                    {
                        string strTime = string.Empty;
                        if (string.IsNullOrEmpty(this.hdnTimeValue.Value))
                        {
                            strTime = "";
                        }
                        else
                        {
                            strTime = this.hdnTimeValue.Value;
                        }
                        if (!string.IsNullOrEmpty(OutboundServiceClientProxy.GetInstance().ShippedByOrderID(OrderIDs, strTime)))
                        {
                            base.ShowMsgLabel(this.lblMsg, string.Format(base.GetGlobalMsgResource("F7600_008"), this.txtOrderID.Text.Trim()));
                            this.SetShippingOrderInfo2From();
                            if (this.ddlStatus.SelectedValue == "Shipped")
                            {
                                List<string> mailList = new List<string> {
                                    DateTime.Now.ToString(),
                                    this.txtOrderID.Text,
                                    base.UserInfo.UserName
                                };
                                UserMstInfo user = BaseInfoServiceClientProxy.GetInstance().GetInfoByID(this.hdnCreatedBy.Value, "USER_MST") as UserMstInfo;
                                if (user != null)
                                {
                                    base.SandMail("Shipping", mailList, user.Email);
                                }
                            }
                        }
                        else
                        {
                            base.ShowMsgLabel(this.lblMsg, base.GetGlobalMsgResource("F7600_009"));
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                SysLog.GetInstance().LogError(ex);
                base.ShowMsgLabel(this.lblMsg, ex.Message);
            }
            finally
            {
                ScriptManager.RegisterStartupScript(this.Page, base.GetType(), "ShippingPage", "<script language='javascript'>$.unblockUI();</script>", false);
            }
        }

        private void SetShippingOrderInfo2From()
        {
            string OrderID = this.hdnOrderID.Value.ToString();
            OrdersInfo orderInfo = OutboundServiceClientProxy.GetInstance().GetOrdersInfoByOrderID(OrderID);
            base.DataEntityViewState = orderInfo;
            if (orderInfo != null)
            {
                this.txtOrderID.Text = orderInfo.OrderID;
                this.hdnPalletAudit.Value = orderInfo.IsPalletAudit;
                this.ddlStatus.SelectedValue = orderInfo.Status;
                this.ddlType.SelectedValue = orderInfo.Type;
                this.ddlType_SelectedIndexChanged(null, null);
                this.txtOrderDate.Text = base.GetPreferenceShortDate(orderInfo.OrderDate);
                this.txtOwnerID.Text = orderInfo.OwnerID;
                this.txtOwnerID.Enabled = false;
                this.imgOwnerID.Visible = false;
                this.txtOrderGroup.Text = orderInfo.OrderGroup;
                this.txtReferenceNum.Text = orderInfo.ReferenceNum;
                this.txtRequestShipDate.Text = base.GetPreferenceShortDate(orderInfo.RequestedShipDate);
                this.ddlPriority.SelectedValue = orderInfo.Priority;
                if (!string.IsNullOrEmpty(orderInfo.IntransitID) && (this.ddlWareHouseID.Items.Count > 0))
                {
                    this.ddlWareHouseID.SelectedValue = orderInfo.DestWhDbID;
                }
                this.txtIntransitID.Text = orderInfo.IntransitID;
                this.ddlWareHouseID.Enabled = false;
                this.txtIntransitID.Enabled = false;
                this.txtExternOrderID.Text = orderInfo.ExternOrderID;
                this.txtActualShipDate.Text = string.IsNullOrEmpty(base.GetPreferenceShortDate(orderInfo.ActualShipDate)) ? base.GetPreferenceShortDate(DateTime.Now) : base.GetPreferenceShortDate(orderInfo.ActualShipDate);
                this.txtExternOrderID2.Text = orderInfo.ExternalOrderId2;
                this.txtDeliveryDate.Text = base.GetPreferenceShortDate(orderInfo.DeliveryDate);
                this.txtConsigneeID.Text = orderInfo.ConsigneeID;
                this.txtCCompany.Text = orderInfo.CCompany;
                if ((orderInfo.OrderDetailInfos != null) && (orderInfo.OrderDetailInfos.Count > 0))
                {
                    this.hdnLineID.Value = (orderInfo.OrderDetailInfos[orderInfo.OrderDetailInfos.Count - 1].LineID + 10).ToString();
                }
                else
                {
                    this.hdnLineID.Value = "10";
                }
                base.BindData2GridView(this.gvOrderDetail, orderInfo.OrderDetailInfos);
                base.BindData2GridView(this.gvdShipmentContainer, orderInfo.ShipmentContainerInfos);
                base.BindData2GridView(this.gvShippedDetail, orderInfo.ShippedDetailInfos);
                this.EncaseNesting();
            }
        }

        protected void txtBarcode_OnTextChanged(object sender, EventArgs e)
        {
            if (!string.IsNullOrEmpty(this.txtBarcode.Text))
            {
                SkuInfo skuInfo = CommoneMethodServiceClientProxy.GetInstance().GetSkuByBarcode(this.txtBarcode.Text);
                if (skuInfo != null)
                {
                    this.txtSkuID.Text = skuInfo.SkuID;
                    this.txtValue.Text = base.GetPreferenceDigit(skuInfo.SalePrice);
                    this.InsertShipmentContainerData();
                }
                else
                {
                    base.ShowMsgLabel(this.lblMsg, base.GetGlobalMsgResource("F7600_020"));
                }
            }
            ScriptManager.RegisterStartupScript(this.Page, base.GetType(), "ShippingPage", "<script language='javascript'>setTab('one',5,5);</script>", false);
        }

        protected void txtContainerID_OnTextChanged(object sender, EventArgs e)
        {
            if (!string.IsNullOrEmpty(this.txtContainerID.Text.Trim()))
            {
                string strIsActive = string.Empty;
                OrdersInfo orderInfo = OutboundServiceClientProxy.GetInstance().GetOrdersInfoAndDetailListByID(this.txtOrderID.Text, this.txtContainerID.Text);
                this.Session.Add("PageOrderInfo", orderInfo);
                List<ShipmentContainerInfo> ShipmentContainerList = new List<ShipmentContainerInfo>();
                foreach (ShipmentContainerInfo info in orderInfo.ShipmentContainerInfos)
                {
                    if (info.ContainerID == this.txtContainerID.Text)
                    {
                        this.txtContainerType.Text = info.ContainerType;
                        this.txtTotalQty.Text = info.TotalQty.ToString();
                        this.txtRemark.Text = info.Remark;
                        this.txtHeight.Text = info.Height.ToString();
                        this.txtLength.Text = info.Length.ToString();
                        this.txtVolume.Text = info.Volume.ToString();
                        this.txtWeight.Text = info.Weight.ToString();
                        this.txtWidth.Text = info.Width.ToString();
                        this.txtValue.Text = info.Value.ToString();
                        if (info.IsActive == "Y")
                        {
                            ShipmentContainerList.Add(info);
                        }
                        else
                        {
                            strIsActive = "Y";
                        }
                    }
                }
                if (ShipmentContainerList.Count > 0)
                {
                    this.txtBarcode.Enabled = true;
                    this.txtQty.Enabled = true;
                    this.txtBarcode.Focus();
                    base.PageQueryEntityViewState = ShipmentContainerList;
                }
                else if (strIsActive != "Y")
                {
                    this.txtContainerType.Enabled = true;
                    this.txtContainerType.Text = "";
                    this.imgContainerType.Visible = true;
                    this.txtRemark.Text = "";
                    this.txtRemark.Enabled = true;
                    this.txtHeight.Enabled = true;
                    this.txtHeight.Text = "";
                    this.txtLength.Enabled = true;
                    this.txtLength.Text = "";
                    this.txtVolume.Enabled = true;
                    this.txtVolume.Text = "";
                    this.txtWeight.Enabled = true;
                    this.txtWeight.Text = "";
                    this.txtWidth.Enabled = true;
                    this.txtWidth.Text = "";
                    this.txtValue.Text = "";
                    this.txtSkuID.Text = "";
                    this.txtBarcode.Text = "";
                    this.txtBarcode.Enabled = true;
                    this.txtQty.Enabled = true;
                }
                else
                {
                    this.txtBarcode.Enabled = true;
                    this.txtBarcode.Focus();
                    this.txtQty.Enabled = true;
                }
                base.BindData2GridView(this.gvdShipmentContainers, ShipmentContainerList);
            }
            else
            {
                this.txtContainerType.Enabled = false;
                this.txtContainerType.Text = "";
                this.imgContainerType.Visible = false;
                this.txtRemark.Text = "";
                this.txtRemark.Enabled = false;
                this.txtHeight.Enabled = false;
                this.txtHeight.Text = "";
                this.txtLength.Enabled = false;
                this.txtLength.Text = "";
                this.txtVolume.Enabled = false;
                this.txtVolume.Text = "";
                this.txtWeight.Enabled = false;
                this.txtWeight.Text = "";
                this.txtWidth.Enabled = false;
                this.txtWidth.Text = "";
                this.txtValue.Text = "";
                this.txtBarcode.Text = "";
                this.txtSkuID.Text = "";
                this.txtBarcode.Enabled = false;
                this.txtQty.Enabled = false;
                base.BindData2GridView(this.gvdShipmentContainers, new List<ShipmentContainerInfo>());
            }
            ScriptManager.RegisterStartupScript(this.Page, base.GetType(), "ShippingPage", "<script language='javascript'>setTab('one',5,5);</script>", false);
        }
    }
}

